package com.ctshk.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 审批状态
 * 工作流-审批状态三种：审批中，审批通过，审批不通过
 * 供应商预订-团队预订四种：待提交，审批中，审批通过，审批不通过
 * 自由行-取消状态三种：审批中，审批通过，审批不通过
 * 自由行-退款记录状态四种：审批中，审批通过，审批不通过，退款成功
 *
 * @author 谢诗宏
 * @description 审批流程状态
 * @date 2021/3/11
 */
@AllArgsConstructor
public enum ApprovalStatus {
    // 审批所有状态
    RECALL(0, "撤回"),
    WAIT_SUBMIT(1, "待提交"),
    REVIEWING(2, "审批中"),
    REVIEW_YES(3, "审批通过"),
    REVIEW_NO(4, "审批不通过"),
    REFUND_SUCCESS(5, "退款成功"),
    LEAVE_GROUP_SUCCESS(6, "退团成功"),
    REJECTED_SUCCESS(7,"已駁回");

    @Getter
    @Setter
    private Integer code;

    @Getter
    @Setter
    private String value;

    public static boolean isCheckStatus(Integer status) {
        return status == ApprovalStatus.RECALL.getCode()
                || status == ApprovalStatus.REVIEW_YES.getCode()
                || status == ApprovalStatus.REVIEW_NO.getCode();
    }

    public static boolean isBothStatus(Integer status) {
        return status == ApprovalStatus.REVIEW_YES.getCode()
                || status == ApprovalStatus.REVIEW_NO.getCode();
    }

    public static String parseValue(int code) {
        for (ApprovalStatus type : ApprovalStatus.values()) {
            if (Objects.equals(type.code, code)) {
                return type.getValue();
            }
        }
        return null;
    }

    public static ApprovalStatus getDefined(Integer code) {
        return Arrays.stream(ApprovalStatus.values())
                .filter(enums -> enums.getCode() == code)
                .findFirst().orElse(null);
    }

}
